from langchain_community.embeddings import DashScopeEmbeddings

from lab_2_conf_manage_neo4j import conf_neo4j
from langchain_community.vectorstores import Neo4jVector

# Add both keyword and vector retrieval to documents
def get_vector_index():
    vector_index = Neo4jVector.from_existing_graph(
        DashScopeEmbeddings(
            dashscope_api_key='sk-780da555f1714f4b81c1bfc553cfd74a',
            model="text-embedding-v3"
        ),
        search_type = "hybrid",
        node_label = "Document",
        text_node_properties = ["text"],
        embedding_node_property = "embedding"
    )
    return vector_index


if __name__ == "__main__":
    conf_neo4j()
    vector_idx = get_vector_index()
    print("Vector Index Build successfully...")

    question = "Who is Elizabeth I?"
    result = vector_idx.similarity_search(question)
    print(result[0].metadata.get('summary'))

    
